﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace Hyt.Core
{
    public static class TypeExtension
    {
        public static object GetCustomAttribute(this Type @this, Type attribute, bool inherit)
        {
            var attrs = @this.GetCustomAttributes(attribute, inherit);
            if (attrs.Any())
            {
                return attrs[0];
            }
            return null;
        }

        public static T GetCustomAttribute<T>(this Type @this, bool inherit) where T : Attribute
        {
            var attr = GetCustomAttribute(@this, typeof(T), inherit);
            if (attr == null)
            {
                return default(T);
            }
            return (T)attr;
        }
    }
}
